package com.designed.pattern.addition.strategyfactoryDecorate;

/**
 * @author yifei
 * @description 策略模式，将子类通过构造方法添加。实现不同的功能
 * @date 2024/1/2
 **/
public class CashContext {

    private ISale cs;

    public CashContext(int cashType) {
        switch (cashType) {
            case 1:
                cs = new CashRebate(1);
                break;
            case 2:
                cs = new CashRebate(0.8);
                break;
            case 3:
                cs = new CashRebate(0.6);
                break;
            case 4:
                cs = new CashReturn(300d, 50d);
            case 5:
                CashReturn cn1 = new CashReturn(300d, 100d);
                cn1.decorate(new CashRebate(0.8));
                cs = cn1;
                break;
            case 6:
                CashRebate cr2 = new CashRebate(0.8);
                cr2.decorate(new CashReturn(300d, 100d));
                cs = cr2;
                break;
        }
    }

    public double getResult(double price, int num) {
        return this.cs.acceptCash(price, num);
    }
}
